@echo off

REM 显示当前CMD的编码
chcp

REM 创建一个新的正确编码的批处理文件
echo @echo off > new_clean_build.bat
echo. >> new_clean_build.bat
echo REM 配置UTF-8编码 >> new_clean_build.bat
echo chcp 65001 ^> nul >> new_clean_build.bat
echo. >> new_clean_build.bat
echo REM 创建Python虚拟环境 >> new_clean_build.bat
echo echo 创建Python虚拟环境... >> new_clean_build.bat
echo python -m venv venv >> new_clean_build.bat
echo. >> new_clean_build.bat
echo REM 激活虚拟环境 >> new_clean_build.bat
echo echo 激活虚拟环境... >> new_clean_build.bat
echo call venv\Scripts\activate.bat >> new_clean_build.bat
echo. >> new_clean_build.bat
echo REM 安装必要的依赖 >> new_clean_build.bat
echo echo 安装必要的依赖... >> new_clean_build.bat
echo pip install --upgrade pip >> new_clean_build.bat
echo pip install pandas numpy openpyxl xlrd pyinstaller >> new_clean_build.bat
echo. >> new_clean_build.bat
echo REM 打包Python脚本为可执行文件 >> new_clean_build.bat
echo echo 开始打包Python脚本为可执行文件... >> new_clean_build.bat
echo pyinstaller --onefile --windowed --icon=none --name="Excel搜索工具" --add-data="excel_search_tool.py;." excel_search_tool.py >> new_clean_build.bat
echo. >> new_clean_build.bat
echo REM 复制生成的exe文件到当前目录 >> new_clean_build.bat
echo echo 复制生成的可执行文件到当前目录... >> new_clean_build.bat
echo copy /Y dist\Excel搜索工具.exe .\ >> new_clean_build.bat
echo. >> new_clean_build.bat
echo REM 清理临时文件 >> new_clean_build.bat
echo echo 清理临时文件... >> new_clean_build.bat
echo rd /s /q build >> new_clean_build.bat
echo rd /s /q dist >> new_clean_build.bat
echo rd /s /q __pycache__ >> new_clean_build.bat
echo del /q Excel搜索工具.spec >> new_clean_build.bat
echo. >> new_clean_build.bat
echo REM 停用虚拟环境 >> new_clean_build.bat
echo echo 停用虚拟环境... >> new_clean_build.bat
echo call venv\Scripts\deactivate.bat >> new_clean_build.bat
echo. >> new_clean_build.bat
echo REM 完成提示 >> new_clean_build.bat
echo echo. >> new_clean_build.bat
echo echo 打包完成！ >> new_clean_build.bat
echo echo 可执行文件 "Excel搜索工具.exe" 已生成在当前目录。 >> new_clean_build.bat
echo echo 按任意键退出... >> new_clean_build.bat
echo pause ^> nul >> new_clean_build.bat

echo 已创建新的正确编码的批处理文件: new_clean_build.bat
echo 请使用此文件进行打包操作
echo 按任意键退出...
pause > nul